package com.cjm.one.order.client;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.constant.SecurityConstants;
import com.cjm.one.common.constant.ServerConstants;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.base.PageVo;
import com.cjm.one.model.order.dto.OrderChartItem;
import com.cjm.one.model.order.dto.OrderNoRefundDto;
import com.cjm.one.model.order.dto.OrderOperateDTO;
import com.cjm.one.model.order.dto.OrderStatusDto;
import com.cjm.one.model.order.entity.OrderInfo;
import com.cjm.one.model.order.enums.OrderParamsTypeEnum;
import com.cjm.one.model.order.enums.OrderStatusEnum;
import com.cjm.one.model.order.enums.PayTypeEnum;
import com.cjm.one.model.order.vo.OrderInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@FeignClient(value = ServerConstants.SERVER_ONE_ORDER)
public interface OrderInfoClient {

    @GetMapping("/admin/order/info/list")
    @Operation(summary = "订单列表")
    Result<PageVo<OrderInfoVo>> list(
            @RequestParam(value = "current", required = true, defaultValue = "1") Long current,
            @RequestParam(value = "size", required = true, defaultValue = "10") Long size,
            @RequestParam(value = "userId",required = false) Long userId,
            @RequestParam(value = "orderNo",required = false) String orderNo,
            @RequestParam(value ="status",required = false) OrderStatusEnum status,
            @RequestParam(value ="payStatus",required = false) PayTypeEnum payStatus,
            @RequestParam(value ="userName",required = false) String userName,
            @RequestParam(value ="createTimeStart",required = false) String createTimeStart,
            @RequestParam(value ="createTimeEnd",required = false) String createTimeEnd,
            @RequestParam(value ="phone",required = false) String phone,
            @RequestParam(value ="goodsName",required = false) String goodsName
    );
    @GetMapping("/admin/order/info/{id}")
    @Operation(summary = "订单详情")
    Result<OrderInfoVo> getOrderInfo(@PathVariable("id") Long id );

    @DeleteMapping("/admin/order/info/delete/{id}")
    @Operation(summary = "删除订单")
    Result<Boolean> delete(@PathVariable("id") Long id);

    @DeleteMapping("/admin/order/info/batch")
    @Operation(summary = "批量删除订单")
    Result<Boolean> deleteBatch(@RequestParam("ids") Long[] ids);

    @PostMapping("/admin/order/info/refund/{id}")
    @Operation(summary = "退款")
    Result<Boolean> refund(@PathVariable("id") Long id);

    @PutMapping("/admin/order/info/status/{id}")
    @Operation(summary = "修改订单状态")
    Result<Boolean> updateStatus(@PathVariable("id") Long id, @RequestParam("status") OrderStatusEnum status);
    @GetMapping("/admin/order/info/test")
    @Operation(summary = "退款")
    Result<OrderStatusEnum> test();

    @PutMapping("/admin/order/info/noRefund")
    @Operation(summary = "拒绝退款接口")
    Result<Boolean> noRefund(@RequestBody OrderNoRefundDto orderNoRefundDto);

    @GetMapping("/admin/order/info/summary")
    @Operation(summary = "订单统计")
    Result<Map<String, Object>> getOrderSummary(@RequestParam(defaultValue = "30d") String timeRange);

    @GetMapping("/admin/order/info/chart")
    @Operation(summary = "获取图表数据")
    Result<List<OrderChartItem>> getOrderChart(
            @RequestParam(defaultValue = "30d") String timeRange);

    @GetMapping("/countPaidUsers")
    @Operation(summary = "统计支付用户数")
    Result<Long> countPaidUsers(@RequestParam(name = "startTime") LocalDateTime startTime, @RequestParam(name = "endTime") LocalDateTime endTime, @RequestHeader(SecurityConstants.FROM_SOURCE) String fromSource);

    @GetMapping("/app/order/info/list")
    @Operation(summary = "用户订单信息列表")
    Result<Page<OrderInfoVo>> list(@RequestParam(value = "current", defaultValue = "1") Long current,
                                          @RequestParam(value = "size", defaultValue = "10") Long size ,
                                   @RequestParam(value = "type", required = false) OrderParamsTypeEnum type);
    @PostMapping("/app/order/info/add")
    @Operation(summary = "添加订单")
    Result<String> add(@RequestBody OrderOperateDTO orderOperateDTO);
    /**
     * @description: 更新订单
     * @author: cjm
     * @date: 2025/4/2 20:34
     * @param: [orderInfoVo]
     * @return: com.cjm.one.common.result.Result<java.lang.Boolean>
     **/
    @PostMapping("/app/order/info/update")
    @Operation(summary = "更新订单")
    Result<Boolean> update(@RequestBody OrderInfoVo orderInfoVo);

    @DeleteMapping("/app/order/info/delete/{id}")
    @Operation(summary = "删除订单")
    Result<Boolean> appdelete(@PathVariable Long id);

    @GetMapping("/app/order/info/{id}")
    @Operation(summary = "查询订单")
    Result<OrderInfoVo> getAppUserByOrderId(@PathVariable Long id);

    @GetMapping("/app/order/info/ByorderNo/{orderNo}")
    @Operation(summary = "根据订单号查询")
    Result<OrderInfoVo> getByorderNo(@PathVariable String orderNo, @RequestHeader(SecurityConstants.FROM_SOURCE) String fromSource);
    /**
     * @description: 更新订单内部调用
     * @author: cjm
     * @date: 2025/4/2 20:34
     * @param: [orderInfo, fromSource]
     * @return: com.cjm.one.common.result.Result<java.lang.Boolean>
     **/
    @PostMapping("/app/order/info/update/order")
    @Operation(summary = "更新订单-内部调用")
    Result<Boolean> updateOrder(@RequestBody OrderInfoVo orderInfo, @RequestHeader(SecurityConstants.FROM_SOURCE) String fromSource);
    /**
     * @description: 修改订单状态
     * @author: cjm
     * @date: 2025/4/2 20:34
     * @param: [orderStatusDto]
     * @return: com.cjm.one.common.result.Result<java.lang.Boolean>
     **/
    @PostMapping("/app/order/info/update/status")
    @Operation(summary = "更新订单")
    Result<Boolean> updateOrderStatus(@RequestBody OrderStatusDto orderStatusDto);
}
